# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.18.1)

project("libleveldb")

set(LEVELDB_SRC_DIR "${PROJECT_SOURCE_DIR}/leveldb")
set(LEVELDB_BUILD_DIR "${PROJECT_SOURCE_DIR}/leveldb/out/${ANDROID_ABI}")

file(MAKE_DIRECTORY ${LEVELDB_BUILD_DIR})

file(GLOB list ${PROJECT_SOURCE_DIR}/jni/*.cc)

add_subdirectory(
        ${LEVELDB_SRC_DIR}
        ${LEVELDB_BUILD_DIR}
)

add_library(
        libleveldb
        STATIC
        IMPORTED)

set_target_properties(
        libleveldb
        PROPERTIES IMPORTED_LOCATION
        ${LEVELDB_BUILD_DIR}/libleveldb.a)
add_library(leveldb-android SHARED
        ${list}
        )

find_library(
        log-lib
        log)

include_directories(${LEVELDB_SRC_DIR}/include)
include_directories(${LEVELDB_BUILD_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR})

target_link_libraries(
        leveldb-android
        libleveldb
        android
        ${log-lib})
